package com.itheima.Test07;

import java.util.ArrayList;

public class StudentServiceImpl2 implements StudentService {

    @Override
    public void printAllinfo(ArrayList<Student> students) {
        int boy = 0;
        int girl =0;
        System.out.println("-------------全班全部学生如下----------");
        //遍历获取每个学生
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            System.out.println("姓名："+s.getName()+",性别:"+s.getSex()+",成绩:"+s.getScore());
            if(s.getSex()=='女'){
                girl++;
            }else {
                boy++;
            }
        }
        System.out.println("男生人数是:"+boy+",女士人数是:"+girl);
        System.out.println("班级总人数是:"+students.size());
        System.out.println("-----------------------------------");
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        double maxScore =students.get(0).getScore();
        double minScore =students.get(0).getScore();
        double allscore =0.0;
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            //全部成绩总和
            allscore +=s.getScore();
            if(maxScore<s.getScore()){
                maxScore = students.get(i).getScore();
            }
            if(minScore>s.getScore()){
                minScore = students.get(i).getScore();
            }
        }


        System.out.println("学生最高分是:"+maxScore);
        System.out.println("学生最低分是:"+minScore);
        System.out.println("平均分：" + (allscore - maxScore - minScore) / (students.size() - 2));
    }
}
